<template>
  <div>
    门店名称
    <input type="text" v-model="state.name">
    联系方式
    <input type="text" v-model="state.phone">
    <input type="button" value="查询" @click="show()">
<h2>门店显示</h2>

  </div>
  <table border="1">
    <tr>
      <td>门店名称</td>
      <td>门店位置</td>
      <td>门店联系方式</td>
      <td>门店Logo</td>
      <td>操作</td>
    </tr>
    <tr v-for="item in list">
      <td>{{ item.name }}</td>
      <td>{{ item.address }}</td>
      <td>{{ item.phone }}</td>
      <td>
        <img src="../pic/QQ图片20240222105940.jpg" width="80" height="80">
      </td>
      <td>
        <input type="button" value="删除" @click="dele(item.sid)">
      </td>
    </tr>
  </table>
  共有<span>{{ count }}</span>条
  每页显示<span>{{ state.pageSize }}</span>条
  当前为第<span>{{ state.pageIndex }}</span>/<span>{{ pcount }}</span>
  <input type="button" value="首页" @click="fenye('a')">
  <input type="button" value="上一页" @click="fenye('b')">
  <input type="button" value="下一页" @click="fenye('c')">
  <input type="button" value="尾页" @click="fenye('d')">
</template>

<script setup lang="ts">
import axios from 'axios';
import{reactive,toRefs,onMounted}from'vue'
import { useRoute,useRouter } from 'vue-router';
let router=useRouter();
let route=useRoute();
let data:any=reactive({
  state:{
  name:'',
  phone:'',
  pageIndex:1,
  pageSize:2,
  },
  list:[],
  count:'',
  pcount:''
})
let{state,list,count,pcount}=toRefs(data)
onMounted(()=>{
  show()
})

function show()
{
  let obj={
    pageSize:state.value.pageSize,
    pageIndex:state.value.pageIndex,
    name:state.value.name,
    phone:state.value.phone
  }
  axios({
    url:'/api/DisCount/GetStores',
    method:'get',
    params:obj
  })
  .then(res=>{
    list.value=res.data.data
    count.value=res.data.cc,
    pcount.value=res.data.pp
  })
  .catch(err=>{

  })
}
const fenye=(obj:any)=>{
  switch(obj){
    case"a":
    state.value.pageIndex=1;
    break;
    case"b":
    state.value.pageIndex--;
    break;
    case"c":
    state.value.pageIndex++;
    break;
    case"d":
    state.value.pageIndex.pcount;
    break;
  }
  show()
}
const dele=(sid:any)=>{
  if(confirm("确定要删除吗?"))
{
  let obj={
    sid:sid
  }
  axios({
    url:'/api/DisCount/Delete',
    method:'get',
    params:obj
  })
  .then(res=>{
    if(res.data.data===1)
  {
    alert("删除成功")
  }
  })
  .catch(err=>{

  })
}
}
</script>

<style scoped>

</style>